import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:sainbainu/common/values/colors.dart';
import 'package:sainbainu/common/widgets/widget.dart';

import '../index.dart';

/// hello
class FeedbackCreate extends GetView<FeedbackController> {
  final VoidCallback? onSubmit;
  const FeedbackCreate({
    Key? key,
    this.onSubmit,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('我要反馈'.tr),
        automaticallyImplyLeading: false,
        // leading: IconButton(
        //   onPressed: () => Get.back(),
        //   icon: const Icon(Icons.close),
        // ),
        // shape: const RoundedRectangleBorder(
        //   borderRadius: BorderRadius.only(
        //     topLeft: Radius.circular(20),
        //     topRight: Radius.circular(20),
        //   ),
        // ),
      ),
      body: _buildWrapper([
        _buildInput(
          labelText: '输入反馈内容'.tr,
          maxLines: 3,
          controller: controller.state.contentController,
        ),
        const SizedBox(height: 15),
        Container(
          width: double.infinity,
          padding: const EdgeInsets.all(10),
          decoration: BoxDecoration(
            color: AppColors.page,
            borderRadius: BorderRadius.circular(10),
          ),
          child: ImageUploader(
            controller: controller.state.imageUploaderController,
            maxCount: 3,
            uploadIconAlignment: Alignment.center,
            selectedCallback: (images) {
              controller.state.feedbackImages = images;
            },
          ),
        ),
        const SizedBox(height: 15),
        SizedBox(
          width: double.infinity,
          height: 44,
          child: ElevatedButton(
            onPressed: onSubmit,
            style: ElevatedButton.styleFrom(
              backgroundColor: AppColors.danger,
              foregroundColor: Colors.white,
              enableFeedback: true,
            ),
            child: Text('确认反馈'.tr),
          ),
        ),
      ]),
    );
  }

  Widget _buildWrapper(List<Widget> children) {
    return SingleChildScrollView(
      physics: const BouncingScrollPhysics(),
      child: Padding(
        padding: const EdgeInsets.all(15),
        child: Container(
          padding: const EdgeInsets.all(15),
          decoration: const BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.all(Radius.circular(10)),
          ),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: children,
          ),
        ),
      ),
    );
  }

  Widget _buildInput({
    required String labelText,
    TextEditingController? controller,
    int maxLines = 1,
    int? maxLength,
  }) {
    return Container(
      decoration: const BoxDecoration(
        borderRadius: BorderRadius.all(Radius.circular(10)),
      ),
      clipBehavior: Clip.antiAlias,
      child: TextField(
        controller: controller,
        decoration: InputDecoration(
          border: InputBorder.none,
          fillColor: AppColors.page,
          filled: true,
          isDense: true,
          labelText: labelText,
          labelStyle: const TextStyle(color: AppColors.active),
          floatingLabelStyle: const TextStyle(color: AppColors.success),
        ),
        keyboardType: TextInputType.text,
        textInputAction: TextInputAction.go,
        cursorColor: AppColors.active,
        cursorErrorColor: AppColors.active,
        cursorHeight: 16,
        maxLines: maxLines,
        maxLength: maxLength,
      ),
    );
  }
}
